# !/usr/bin/env python
# -*- coding: utf-8 -*-
"""
 -------------------------------------------------
    File Name:     user_service.py
    Description:   
 -------------------------------------------------
 """
from app.db.session import get_db
from app.api.v1.crud.user_crud import create_user, get_user_by_username
from app.api.v1.schemas.user import UserCreate
from fastapi import Depends


def register_user(user: UserCreate, db: Depends(get_db)):
    db_user = get_user_by_username(db, user.username)
    if db_user:
        raise Exception("Username already registered")
    return create_user(db, user)
